package swing.renderer;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.lang.reflect.Field;

import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class BooleanRenderer extends Renderer {
	
	JRadioButton on;
	JRadioButton off;

	public BooleanRenderer(Field field, String name, String desctiption, String iconURL,	Object initialValue) {
		super(field, name, desctiption, iconURL, initialValue);

		//setLayout(new GridLayout(1, 3));
		
		on = new JRadioButton("on");
		on.setToolTipText(description);
		
		off = new JRadioButton("off");
		off.setToolTipText(description);
		
		ButtonGroup radioGroup = new ButtonGroup();
		radioGroup.add(on);
		radioGroup.add(off);
		
		boolean bool = (Boolean) initialValue;
		
		on.setSelected(bool);
		off.setSelected(!bool);
		
		on.setName(name);
		on.setPreferredSize(new Dimension(60, 30));
		off.setPreferredSize(new Dimension(60, 30));
		
		JPanel panel = new JPanel();
		panel.setLayout(new GridLayout(1,2));
		panel.add(on);
		panel.add(off);
		add(panel);
	
	
	}
	
	@Override
	public Object getValue() {
		return on.isSelected();
	}
	
	

}
